package com.example.controller;

import com.example.common.Result;
import com.example.entity.Major;
import com.example.entity.Teacher;
import com.example.service.TeacherService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Resource
    private TeacherService teacherService;

    @GetMapping("/selectPage")
    public Result selectPage(Teacher teacher,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Teacher> pageInfo = teacherService.selectPage(teacher,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    //查询特定专业下所属学院的教师，用于班级管理
    @GetMapping("/selectByMajorId")
    public Result listByMajor(@RequestParam Integer majorId) {
        List<Teacher> teachers = teacherService.selectByMajorId(majorId);
        return Result.success(teachers);
    }

    @PostMapping("/insert")
    public Result addTeacher(@RequestBody Teacher teacher) {
        teacherService.addTeacher(teacher);
        return Result.success();
    }
    @PutMapping("/update")
    public Result updateTeacher(@RequestBody Teacher teacher) {
        teacherService.updateTeacher(teacher);
        return Result.success();
    }
    @DeleteMapping("/delete/{teacherId}")
    public Result deleteTeacher(@PathVariable Integer teacherId) {
        teacherService.deleteTeacher(teacherId);
        return Result.success();
    }
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        teacherService.deleteBatch(ids);
        return Result.success();
    }
}
